﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Interfaces;

namespace People.Controllers
{
    public class HomeController : Controller
    {
        private readonly IPeopleBll _peopleBll;
        public HomeController(IPeopleBll peopleBll)
        {
            _peopleBll = peopleBll;
        }

        //
        // GET: /Home/
        [HttpGet]
        public ActionResult Index()
        {
            return View(_peopleBll.ReadAll());
        }

        [HttpPost]
        public ActionResult Index(int min, int max)
        {
            return ModelState.IsValid ? View( _peopleBll.Filter(min, max)) : View(_peopleBll.ReadAll());
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(string name, DateTime birthDate, float weight, float height)
        {
            
           if (ModelState.IsValid && _peopleBll.Create(name, birthDate, weight, height))
            {
                return Redirect("Index");
            }
            return View();
        }

        public ActionResult GridJs()
        {
            return View();
        }
        [HttpGet]
        public JsonResult List()
        {
            List<int> ids = new List<int>();
            List<string> names = new List<string>();
            List<string> emails = new List<string>();
          
            //foreach (var user in db.Users.ToList())
            //{
            //    ids.Add(user.Id);
            //    names.Add(user.Name);
            //    emails.Add(user.Email);
            //}
            var toret = new
           {

                users = _peopleBll.ReadAll()
            };
            return Json(toret, JsonRequestBehavior.AllowGet);
        }
    } 
}
